#coding:utf-8
from rest_framework.fields import IntegerField,BooleanField
from rest_framework.serializers import ModelSerializer, Serializer
from erp_system.models import RolesModel, PermissionsModel
from MSB_ERP.apps.erp_system.serializer.Permissions_Serializer import PermissionsSerializer
class BaseRolesSerializer(ModelSerializer):
    """
    普通的序列化类，支持：新增，修改角色名字，删除，查询

    """
   # many = True 时传入的参数需要包含多个对象

    permissions=PermissionsSerializer(many=True,read_only=True)
    class Meta:
        model=RolesModel
        fields = '__all__'


class RolesPartialSerializer(ModelSerializer):
    #用于，给某个角色批量授权的序列化

    class Meta:
        model=RolesModel
        fields = ['id','permissions']

class RoleSetPermissionSerializer(Serializer):
    #用于，给某一个角色，单一授权，也包括取消单一授权
    #角色ID
    role_id=IntegerField(write_only=True,required=True)
    #权限ID
    permission_id=IntegerField(write_only=True,required=True)
    #是否新授与权限(True)，还是取消
    is_create = BooleanField(write_only=True, required=True)
















